//
// InformationBar.cs
//
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
//

using System;
using System.Collections.Generic;

using Gtk;

using Dashboard.Util;

namespace Dashboard.Mint.Widgets {

	public class InformationBar : Gtk.Alignment {

		private Image image = null;
		private Label title = null;
		private Label text = null;

		private Box actions = null;

		public InformationBar () : base (0.0f, 0.5f, 1.0f, 1.0f)
		{
			// Fancy hack to get tooltip-like background

			Window temp = new Window (WindowType.Popup);
			temp.Name = "gtk-tooltips";
			temp.EnsureStyle ();

			base.AppPaintable = true;
			base.BorderWidth = 10;
			base.Style = temp.Style;
			
			// Image

			image = new Gtk.Image ();

			Alignment alignment = new Alignment (0.5f, 0.0f, 0.0f, 0.0f);
			alignment.Add (image);

			// Title and text

			title = new Label ();
			title.Xalign = 0.0f;

			text = new Label ();
			text.Xalign = 0.0f;
			text.Yalign = 0.0f;
			text.Wrap = true;
			text.LineWrap = true;

			VBox vbox = new VBox (false, 5);
			vbox.PackStart (title, false, true, 0);
			vbox.PackStart (text, true, true, 0);

			// Pack contents

			HBox hbox = new HBox (false, 10);
			hbox.PackStart (alignment, false, true, 0);
			hbox.PackStart (vbox, true, true, 0);

			// Actions

			actions = new HBox (false, 3);

			alignment = new Alignment (1.0f, 1.0f, 0.0f, 0.0f);
			alignment.Add (actions);
	
			vbox = new VBox (false, 5);
			vbox.PackStart (hbox, true, true, 0);
			vbox.PackStart (alignment, false, true, 0);

			Add (vbox);
		}

		public void AddAction (string action, EventHandler handler)
		{
			Button b = new Button (action);
			b.Clicked += handler;

			actions.PackStart (b, false, true, 0);
		}
		
		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
		{
			if (!IsDrawable)
				return true;

			Cairo.Context gr = Gdk.CairoHelper.Create (evnt.Window);

			CairoFu.RoundedRectangle (gr, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height, 3);
			gr.Color = CairoFu.GdkColorToCairoColor (Style.Backgrounds [(int)Gtk.StateType.Normal]);
			gr.Fill ();

			CairoFu.RoundedRectangle (gr, Allocation.X + 0.5, Allocation.Y + 0.5, Allocation.Width - 1, Allocation.Height - 1, 3);
			gr.Color =  CairoFu.GdkColorToCairoColor (Style.DarkColors [(int)Gtk.StateType.Normal]);
			gr.LineWidth = 1;
			gr.Stroke ();

			CairoFu.DisposeContext (gr);
			
			return base.OnExposeEvent (evnt);
		}

		public Gdk.Pixbuf Icon {
			set { image.Pixbuf = value; }
		}

		public string Title
		{
			set { title.Markup = "<b>" + value + "</b>"; }
		}

		public string Text {
			set { text.Markup = value; }
		}
	}
}
